﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using University.Workshop.DataAccess;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for OfferManagerTest and is intended
    ///to contain all OfferManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class OfferManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for MakeAOffer
        ///</summary>
        [TestMethod()]
        public void MakeAOfferTest()
        {
            string email = "alfaro.natalia.lorena@gmail.com";
            UserRegistrationManager.RegisterUser("Natalia", "Alfaro", 'F', DateTime.Now, "alfaro.natalia.lorena@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("Toy Story 3 Original DVD", "10", "sbfjksfksb snflsnlfskf sfnlsnflsnflsfsdkoef dojgdnvkdnvkndkvnkdvd snfsnefoeofornfonsk snfksnfknsfkn", "Electronics", false, "Dollars", user.Id, "1");
            long productId = product.ProductId;
            UserRegistrationManager.RegisterUser("Correo", "Prueba", 'F', DateTime.Now, "lqs.correo.prueba@gmail.com", "loquesea123", "loquesea123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            string buyerEmail = "lqs.correo.prueba@gmail.com";
            User buyer = UserDataAccess.GetUserByEmail(buyerEmail);
            long buyerId = buyer.Id;
            string offerPrice = "90";
            DateTime offerDate = DateTime.Now;
            string message = "muy buen producto pero el precio un poco caro";
            Offer offer= new Offer();
            offer=OfferManager.MakeAOffer(productId, buyerId, offerPrice, offerDate, message);
            Assert.AreNotEqual(null, offer);
        }

        /// <summary>
        ///A test for ModifyOffer
        ///</summary>
        [TestMethod()]
        public void ModifyOfferTest()
        {
            string email = "alfaro.natalia.lorena@gmail.com";
            UserRegistrationManager.RegisterUser("Natalia", "Alfaro", 'F', DateTime.Now, "alfaro.natalia.lorena@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("Green and grey Sweater", "100", "sflsjdfkjsdlkfjdslkjflksdj flkdsjflkdsjflkdsjflkdsj fldsjfldsjfljdsljfldfjldjfldjfljdljfldjgljdfl", "Fashion", false, "Dollars", user.Id, "1");
            long productId = product.ProductId;
            UserRegistrationManager.RegisterUser("Correo", "Prueba", 'F', DateTime.Now, "lqs.correo.prueba@gmail.com", "loquesea123", "loquesea123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            string buyerEmail = "lqs.correo.prueba@gmail.com";
            User buyer = UserDataAccess.GetUserByEmail(buyerEmail);
            long buyerId = buyer.Id;
            string offerPrice = "90";
            DateTime offerDate = DateTime.Now;
            string message = "muy buen producto pero el precio un poco caro";
            Offer offer = new Offer();
            offer = OfferManager.MakeAOffer(productId, buyerId, offerPrice, offerDate, message);
            string secondOffer = "95";
            string status = "Declined";
            bool condition = false;
            offer = OfferManager.ModifyOffer(offer, secondOffer, status, condition);
            Assert.AreNotEqual(null, offer);
        }
    }
}
